package com.vitabuybuy.tv.ui.mine

import android.os.Bundle
import androidx.lifecycle.Observer
import androidx.recyclerview.widget.LinearLayoutManager
import com.library.common.base.BaseActivity
import com.vitabuybuy.tv.R
import com.vitabuybuy.tv.databinding.ActivityActivityRewardsBinding
import com.vitabuybuy.tv.ui.WebViewActivity
import com.vitabuybuy.tv.ui.mine.adapter.ActivityRewardsAdapter
import com.vitabuybuy.tv.ui.mine.viewmodel.MineViewModel

class ActivityRewardsActivity : BaseActivity<MineViewModel, ActivityActivityRewardsBinding>() {
    override val isUseBaseTitleBar: Boolean
        get() = true
    override val layoutId: Int
        get() = R.layout.activity_activity_rewards

    private val mAdapter by lazy { ActivityRewardsAdapter() }

    override fun initView(savedInstanceState: Bundle?) {
        setTitle(getString(R.string.activity_reward))
        mBinding.listview.apply {
            adapter = mAdapter
            layoutManager = LinearLayoutManager(mContext)
        }
    }

    override fun observeData() {
        viewModel.getActivityRewards()
        viewModel.activityRewards.observe(this, Observer {
            mAdapter.setNewData(it)
        })
    }

    override fun eventHandling() {
        mAdapter.onClickRuteListener = {
            WebViewActivity.openActivity(mContext,getString(R.string.view_rule),it,-1)
        }
    }

    companion object {
        fun openActivity(mContext: BaseActivity<*, *>) {
            mContext.startActivity(null, ActivityRewardsActivity::class.java)
        }
    }
}
